﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml.Serialization;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace Ch.Admin.Bfs.Sms.Sdmx.Extension.CodeBook.Configuration
{
    [Serializable]
    public class BitmapLogo
    {
        [XmlIgnore]
        public Bitmap MyImage { get; set; }

        [Browsable(false)]
        public byte[] MyImageBytes
        {
            get
            {
                ImageConverter converter = new ImageConverter();
                return (byte[])converter.ConvertTo(MyImage, typeof(byte[]));
            }
            set
            {
                MyImage = new Bitmap(new System.IO.MemoryStream(value));
            }
        }
    }

    [TypeConverter(typeof(InternationalizedLogo.ExpressionConverter))]
    [Serializable]
    public class InternationalizedLogo
    {
        [DescriptionAttribute("Defines the image of the english version of cover logo")]
        public BitmapLogo LogoEN { get; set; }
        [DescriptionAttribute("Defines the image of the genman version of cover logo")]
        public BitmapLogo LogoDE { get; set; }
        [DescriptionAttribute("Defines the image of the french version of cover logo")]
        public BitmapLogo LogoFR { get; set; }
        [DescriptionAttribute("Defines the image of the italian version of cover logo")]
        public BitmapLogo LogoIT { get; set; }


        #region Internal TypeConverter
        public class ExpressionConverter : TypeConverter
        {

            public override bool GetPropertiesSupported(ITypeDescriptorContext context)
            {
                return true;
            }

            public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context,
                object value, Attribute[] attributes)
            {
                PropertyDescriptorCollection properties =
                    TypeDescriptor.GetProperties(value, attributes);

                // Changing the display order
                string[] textOrder = new string[properties.Count];
                textOrder[0] = "LogoEN";
                textOrder[1] = "LogoDE";
                textOrder[2] = "LogoFR";
                textOrder[3] = "LogoIT";
                // Return a sorted list of properties
                return properties.Sort(textOrder);
            }
        }
        #endregion //Internal TypeConverter

        public InternationalizedLogo()
        {
            LogoDE = new BitmapLogo();
            LogoEN = new BitmapLogo();
            LogoFR = new BitmapLogo();
            LogoIT = new BitmapLogo();
        }
    }
}
